package com.company.huisuo.biz.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import com.company.huisuo.base.BaseSingleAdapter
import com.company.huisuo.databinding.ItemWineCardBinding

/**
 * 酒牌卡片适配器
 */
class WineCardAdapter : BaseSingleAdapter<WineCardItem, ItemWineCardBinding>() {

    override val initViewBinding: (LayoutInflater, ViewGroup, Boolean) -> ItemWineCardBinding
        get() = ItemWineCardBinding::inflate

    override fun convert(
        holder: SingleViewHolder<ItemWineCardBinding>, position: Int, item: WineCardItem?
    ) {
        item ?: return

        holder.binding.apply {
            // 检查view是否有翻开标记（动画过程中打的标记）
            val isAnimatingFlip = holder.itemView.getTag(com.company.huisuo.R.id.iv_card_back) as? Boolean ?: false

            // 如果正在动画翻开，不要覆盖当前状态
            if (isAnimatingFlip) {
                return
            }

            // 默认显示背面
            ivCardBack.visibility = android.view.View.VISIBLE
            clCardFront.visibility = android.view.View.GONE

            // 如果卡片已翻开，显示正面
            if (item.isFlipped) {
                ivCardBack.visibility = android.view.View.GONE
                clCardFront.visibility = android.view.View.VISIBLE
                tvCardTitle.text = item.title
                // 这里可以设置icon，暂时使用占位图
            }
        }
    }
}

/**
 * 卡片数据模型
 */
data class WineCardItem(
    val id: Int, val title: String = "亲声密语", var isFlipped: Boolean = false
)
